<?php
/**
 * Created by b17
 * 3/2/12 6:48 PM
 */

namespace G4T\Form\Element;

class DateElement extends \Zend_Form_Element_Text implements ElementInterface, TypeInterface
{
    protected  $_format = 'Y-m-d';

    public function init()
    {
        parent::init();
        $this->addValidator(new \Zend_Validate_Date(array('format' => $this->_format)));
    }

    public function setParams(array $params)
    {

    }

    public function setValue($value)
    {
        if ($value instanceof \DateTime) {
            $value = $value->format($this->_format);
        }
        parent::setValue($value);
    }

    /**
     * Текстовое название типа для jqgrid.
     *
     */
    public function getFormElementType()
    {
        return 'text';
    }
}
